package com.lyhengtongwl.zqsnews.ui.fragment.forward;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.flyco.tablayout.SlidingTabLayout;
import com.lyhengtongwl.zqsnews.R;
import com.lyhengtongwl.zqsnews.adapter.ForwardAdapter;
import com.lyhengtongwl.zqsnews.base.LazyLoadBaseFragment;
import com.lyhengtongwl.zqsnews.ui.fragment.ForwardFragments;
import com.lyhengtongwl.zqsnews.utils.ScreenUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class SelectedArticlesFragment extends LazyLoadBaseFragment {
    @BindView(R.id.stl)
    SlidingTabLayout stl;
    @BindView(R.id.vp)
    ViewPager vp;
    @BindView(R.id.view_status_bar_place)
    View statusBarPlace;
    private List<String> mTitles=new ArrayList<>();
    private List<Fragment> mFragments=new ArrayList<>();

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ViewGroup.LayoutParams params = statusBarPlace.getLayoutParams();
        params.height = ScreenUtil.getStatusBarHeight(getContext());
        statusBarPlace.setLayoutParams(params);
    }

    @Override
    protected void requestData() {
        super.requestData();
        initTab();
    }

    //初始化顶部导航栏
    private void initTab() {
        mTitles.add("推荐");
        mTitles.add("热点");
        mTitles.add("情感");
        mTitles.add("军事");
        mTitles.add("娱乐");
        mTitles.add("推荐");
        mTitles.add("热点");
        mTitles.add("情感");
        mTitles.add("军事");
        mTitles.add("娱乐");
        for (int i = 0; i < mTitles.size(); i++) {
            mFragments.add(new ForwardFragments((i + 1) + ""));
        }

        //new一个适配器
        ForwardAdapter forwardAdapter = new ForwardAdapter(getChildFragmentManager(), mFragments, mTitles);
        //设置ViewPager与适配器关联
        vp.setAdapter(forwardAdapter);
        vp.setOffscreenPageLimit(mTitles.size()-1);
        //设置Tab与ViewPager关联
        stl.setViewPager(vp);
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.fragment_select;
    }

    @Override
    protected void initView(View rootView) {

    }
}
